package com.jh.user.pojo.enums;

/**
 * 用户等级枚举
 *
 * @author Yichuan
 * @version 1.0
 */
public enum UserGrade {

    EMPLOYEE(0, "员工"),

    DIRECTOR(1, "主管"),

    MANAGER(2, "经理"),

    PARTNER(3, "合伙人"),

    AGENT(4, "贴牌代理商"),

    ;

    final short value;
    final String desc;

    UserGrade(int value, String desc) {
        this.value = (short) value;
        this.desc = desc;
    }

    public short getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static <T extends Number> UserGrade of(T n) {
        short val;
        if (n == null || (val = n.shortValue()) < 0) {
            return null;
        }
        for (UserGrade grade: values()) {
            if (grade.getValue() == val)
                return grade;
        }
        return null;
    }
}
